/**
 * Created by Administrator on 2017/6/27.
 */

const app = require('express')();
const cookieParser = require('cookie-parser');
const session = require('express-session');
const bodyParser = require("body-parser");
const log = require('../util/log.js');
const login = require('./login.js');
const pay = require('./pay.js');

const argv = process.argv.splice(2);
const httpPort = argv[0];

app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({
    secret: '12345',
    //name: 'testapp',   //这里的name值得是cookie的name，默认cookie的name是：connect.sid
    cookie: {maxAge: (1000 * 60 * 15)},  //设置maxAge是80000ms，即80s后session和相应的cookie失效过期
    resave: false,
    saveUninitialized: true,
}));

app.listen(httpPort, function () {
    log.p('登陆和充值服务器HTTP启动:' + httpPort);
});

//建立登陆路由
app.get('/login', login.run);
app.post('/login', login.run);
//建立购买回调路由
app.get('/payCallback', pay.callback);
app.post('/payCallback', pay.callback);


//建立基础路由
app.get('*', function (req, res) {
    res.send(404).end();
});
app.post('*', function (req, res) {
    res.send(404).end();
});